package lanbo.cj.lmp.activity;

import android.content.SharedPreferences;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.FindListener;
import com.baidu.mapapi.SDKInitializer;

import lanbo.cj.lmp.BaseApplication;
import lanbo.cj.lmp.R;
import lanbo.cj.lmp.bean.KeShi;
import lanbo.cj.lmp.bean.User;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import cn.bmob.im.BmobChat;
import cn.bmob.im.BmobUserManager;

import java.util.List;

/**
 * 引导页
 * 
 */
public class SplashActivity extends Activity {

	private final int DURATION_TIME = 1200;
	private ImageView mImageView;
	public BaseApplication mApplication;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		SDKInitializer.initialize(getApplicationContext());
		setContentView(R.layout.splash);
		BmobChat.getInstance(this).init("94233ad5f7204bb11c2172797970b06e");
		mImageView = (ImageView) findViewById(R.id.welcome);
		startAni();
	}



	private void startAni() {
		AnimationSet aSet = new AnimationSet(true);
		AlphaAnimation alphaAni = new AlphaAnimation(0.1f, 1f);
		alphaAni.setDuration(DURATION_TIME);
		ScaleAnimation scaleAni = new ScaleAnimation(1f, 1.2f, 1f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f,
				Animation.RELATIVE_TO_SELF, 0.5f);
		scaleAni.setDuration(DURATION_TIME);

		aSet.addAnimation(alphaAni);
		aSet.addAnimation(scaleAni);
		aSet.setFillAfter(true);
		mImageView.startAnimation(aSet);
//		if(!mApplication.mLocationClient.isStarted()) mApplication.mLocationClient.start();//启动百度定位服务
		aSet.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				BmobUserManager userManager = BmobUserManager.getInstance(SplashActivity.this);
				if (userManager.getCurrentUser(User.class) != null) {
					intent.setClass(SplashActivity.this, MainActivity.class);
					startActivity(intent);
					finish();
				} else {
					intent.setClass(SplashActivity.this, LoginActivity.class);
					startActivity(intent);
					finish();
				}
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub

			}

		});
	}

}
